import 'package:flutter/material.dart';
import 'package:flutter_yd_simple/Project/SignOrder/WaitSignOrderPage.dart';
import 'package:flutter_yd_simple/Project/SignOrder/ZCWSignOrderPage.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';

class SignOrderBasePage extends StatefulWidget {
  const SignOrderBasePage({super.key});

  @override
  State<SignOrderBasePage> createState() => _SignOrderState();
}

class _SignOrderState extends State<SignOrderBasePage> {
  TextEditingController _editingController = new TextEditingController();
  var textStr = "";

  var titleAry = [{"title":"智程网","icon":"lib/Project/Images/Home/home_item_dis.png"},
                {"title":"待派件","icon":"lib/Project/Images/Home/home_item_sign.png"},
                {"title":"已签收","icon":"lib/Project/Images/Home/home_item_colloct.png"},
                {"title":"异常签收","icon":"lib/Project/Images/Home/home_item_call.png"},
                {"title":"第三方","icon":"lib/Project/Images/Home/home_item_sms.png"},
                {"title":"疑似签收","icon":"lib/Project/Images/Home/home_item_more.png"}];
  @override
  Widget build(BuildContext context) {
    return DefaultTabController ( 
      length: titleAry.length,
      initialIndex: 1,
      child: Scaffold(
        // appBar:PreferredSize(
        //   preferredSize: Size.fromHeight(50), 

          appBar: AppBar(
            
            backgroundColor: Color(0xFFFFFFFF),
            elevation: 0,
            iconTheme: IconThemeData(
              color: Colors.black,
            ),
            actions: [
              Row(
                children: [
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Image.asset("lib/Project/Images/Sign/signList_scan.png",width: 15,height: 15),
                      Text("派件指南",style: TextStyle(fontSize: 9,color: Color(0xFF666666))),
                    ],
                  ),
                  SizedBox(width: 6)
                ],
              )
            ],
            //搜索
            title:Padding(
              padding: EdgeInsets.only(left:0),
              child: Container(
              decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(6)),color: Color(0xFFF2F2F2)),
            height: 28,
            //width: MediaQuery.of(context).size.width,
            alignment: Alignment.center,
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                //搜索输入框
                Expanded(child: Container(
                  height: 28,
                  //decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(16)),color: Colors.white),
                  child: TextField(
                    
                    controller: _editingController,
                    keyboardType: TextInputType.number,
                    maxLines: 1,
                    style: const TextStyle(fontSize: 12),
                    decoration: const InputDecoration(
                      hintText: '运单号/姓名/地址/电话后4位',
                      prefixIcon: Icon(Icons.search),
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.only(top: -3), //这里是关键
                    ),
                    inputFormatters: <TextInputFormatter>[
                      LengthLimitingTextInputFormatter(20)//限制长度
                    ],
                    onChanged: (value) {
                      if(value.length > 5) {
                        Fluttertoast.showToast(msg: "运单号过长",gravity:ToastGravity.CENTER);
                        _editingController.text = value.substring(0,5);
                      }
                      this.setState(() {
                          textStr = _editingController.text;
                      });

                      print("value $_editingController.text");
                    },
                  ),
                )),
                const SizedBox(width: 6),
                GestureDetector(
                  child: Image.asset("lib/Project/Images/Sign/signList_scan.png",width: 18,height: 18),
                  onTap: () {
                    Fluttertoast.showToast(msg: "点击了语音icon",gravity:ToastGravity.CENTER);
                  },
                ),
                const SizedBox(width: 6),
                GestureDetector(
                  child: Image.asset("lib/Project/Images/Sign/signList_scan.png",width: 18,height: 18),
                  onTap: () {
                    Fluttertoast.showToast(msg: "点击了扫描icon",gravity:ToastGravity.CENTER);
                  },
                ),
                const SizedBox(width: 6),
              ],
            ),

          ),
            ),
            bottom: TabBar(
              isScrollable: true,
              unselectedLabelColor: Color(0xFF222222),
              unselectedLabelStyle: TextStyle(fontWeight: FontWeight.w100),
              labelColor: Color(0xFF222222),
              labelStyle: TextStyle(fontWeight: FontWeight.w600),
              indicatorColor: Color(0xFF1678FF),
              indicatorSize: TabBarIndicatorSize.label,
              indicatorPadding: EdgeInsets.only(bottom: 5),
              tabs: [
                for (int i = 0;i < titleAry.length;i++)
                Tab( text: titleAry[i]["title"])
              ]
            ),
          ),
        //),

        body: TabBarView(
          children: [
            ZCWSignOrderDemo(),
            WaitSignOrderPageDemo(),
            Icon(Icons.directions_bike),
            Icon(Icons.directions_car),
            Icon(Icons.directions_transit),
            Icon(Icons.directions_transit),
          ]
        ),
      )
    );
  }
}